Okay, so in today's lesson we are going to continue on with functions.
And I've actually got the function we looked at last time because we're going to edit this a little
bit.
So we're looking at how to customize our functions through parameters okay.
So explain all about what parameters and arguments are and how you can use them okay.
So I'm going to keep the function I used for last lesson okay.
Um and if you're following along you can make your make a function yourself.
And yeah follow on from here.
So let's see what the issue is with this function okay.
So this function is great.
It adds a part in and adds a model inside it.
First in um then it adds a part inside of that model.
Now we also give it some properties.
So we say the color is equal to this, the material is equal to this and so on.
Okay.
Um, but what happens if one of these properties is I want it to change.
So instead of it being a corner wedge shape, I want it to be a ball shape.
Or instead of there being wood planks material, I want to just give it a wood material.
And this can happen in a lot of functions because you might have a function which runs, but you want
it to run with a slight change.
For example, this time the player is called this.
So the player is called.
The player has a different username this time because you want the function to work for all players
with different usernames.
Or this time we want it to work, but the part is has this position instead of that position.
So the key issue of our function is that you can't customize it yet.
And that's how you're going to learn.
That's what we're going to learn how to do today okay.
So a parameter allows you to customize or change some of the values in your function.
So parameters act kind of like variables.
But instead they they are placeholders.
And you only give them the value when you run it later on down here okay.
So let's put in two placeholders.
One for the color and one for the material okay.
I'm also going to change anchor to be false false and change the position and give it a set position.
The reason why I'm doing this is so when it spawns in multiple at once, you can see both of them.
Otherwise they'll just be inside of each other and you won't be able to tell the difference.
So let's say zero 30 zero okay.
So let's put in two values as parameters okay.
So parameters are written inside these pair of brackets or parentheses up here.
So when I was saying um last lesson when we start looking at these different version of functions about
how you just need to write these pair of brackets here, you don't know why, but you just need to.
This is why okay.
Because inside those brackets you put your parameters.
So you just put here the name of your parameter.
Or if you'd like to call it a like a placeholder variable okay.
So I'm going to put one called part material and one called part color okay.
So and I've separated them with a comma because there's two of them in here okay.
And then I just close the bracket and then that's it.
Okay.
Um so the reason why we need these brackets is so we can put any parameters in here, okay.
And even if we don't have any parameters, we still need to tell the function that there aren't any
parameters.
Because if we don't include the brackets, it doesn't know if there are parameters, if that makes sense.
But if you include a empty pair of brackets, it knows there's not supposed to be any parameters there.
So even if there aren't any, you need to tell it.
There's not any.
Not to just let it assume there aren't any.
Okay, hopefully that makes sense.
Um, so we can now put these variables inside of our function okay.
So part material.
Let's swap that out with this material here.
So instead of writing the actual material you want to give it we just say part material like that.
They're saying for the color.
Instead of writing out the color here we just replace it with part color.
And these are our two placeholders which we can change.
Okay.
So all we've done is that we have added in two variables okay, which we are making the color equal
to and the material equal to okay.
And they act as placeholders because currently we don't have a value for part color or the parts material
because they're just.
Placeholders.
There's no values of them just yet.
When we go ahead and run the function down here, that's when we give it its its values and we can see
when we click on it, we need to give it a material value which is in the data type enum dot material,
because we know we're making that equal to the material property.
And we also have to give it a value for the part color parameter.
And that acts as a color three because we're changing the color property.
Okay.
And when you are giving these parameters their values they're called arguments.
So your arguments go inside the bracket pair of brackets here.
And your parameters go inside the pair of brackets here.
Okay.
So let's give it some values.
So for the material let's write enum dot material just as it says up here.
Then we can press dot and choose what we want from the enum.
So let's go for fabric.
For example write a comma space just for readability and then put in a color three value.
And we could say um put in.
Let's change one on the color wheel, this one here for example.
Okay.
And the beauty about this is that you can then run the function again, but with a different set of
values, so we can run it a second time.
But this time, this part I want to have a glass material and we color.
Can be maybe of a pink purple kind of color there instead.
Okay.
So if I run the game, we can hopefully see these two parts be added in.
We can see it's added my two wedges in here, both with different um, yeah.
Both with different properties.
So this one here, um, it has our lapis color and the fabric material.
We can see the fabric material there.
Okay.
And then the other one here has a pink color and instead it has a glass material.
You can see how shiny it is.
It's glass okay.
So they are parameters and arguments okay.
And they really make start to make functions very useful.
Because if you're wanting to write code which is very repetitive, maybe you repeat it quite a lot,
but you only change 1 or 2 values, then.
This is a great example on how you could use that instead.
And functions are so much more useful when you include parameters inside of them as well.
Okay, so this is really a key part on how we go from functions just being, um, a way of making your
code look better to actually really helping you out.
Right.
Stuff.
Okay.
It's still, um, things you can do.
It's still things you can do yourself.
It would just be a bit repetitive.
But next lesson, we're going to start looking at things that you would not be able to do without functions
okay.
And they are events.
So have a play around with that.
And if you've tried out any functions already, maybe go back to those and add some parameters in and
see how you can customize them, because it makes your functions a lot easier to use if you're able
to customize them like this here.
Okay.
And this is actually how I'll just mention this before we finish off, um, this is actually how the
print function works.
Um, so a print function we learned right at the start.
Second lesson, I think it was, um, is the name of our function.
Okay.
And inside here we put a string.
So hello.
For example.
Okay.
Um, now the print function, the.
Yeah, the print function is here.
Okay.
We don't have a separate print function for every single possible thing you add in.
Instead we have one print function.
And you can type inside here what you want to output into the output tab okay.
And you can think of this as an argument because that's exactly what it is.
It's passing this into the print function.
Roadblocks is already made for us okay.
And it's changing the value of this placeholder variable to the string.
Hello.
So it can then output that instead.
So it just hopefully gives you a bit of a better understanding about these functions.
We've learned about how they actually work.
So it's the information the proper word of saying that is an argument okay.
Because that's the value that the placeholder parameter gets.
Okay.
So um, yeah, as I said, um, try out and go to your some of your old functions and add some parameters
and things like that in it just to try these out, okay.
Because next lesson we are going to be looking at events.
And events also contain a bit of parameters.
So you will learn.
You will learn a bit parameters a bit more, but definitely be comfortable with those before you move
on to the next lesson.
Okay?